Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: replace strtobool for local function #128

Merged
merged 2 commits into from
Feb 2, 2022
Merged

fix: replace strtobool for local function #128

merged 2 commits into from
Feb 2, 2022

Conversation

ZandorSabino
Copy link
Contributor

Issue

The distutils module was deprecated in PEP 632.
resolve #127

Solution

Creation of a local function to replace the strtobool function used by distutils.

Copy link
Collaborator

@henriquebastos henriquebastos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Liked the tests. With minor improvements I can merge it.

def test_invalid_value_text():
invalid_list = ["Invalid_Value_1", "1nv4l1d_V4lu3_2", "Invalid_Value_3"]
for value in invalid_list:
with pytest.raises(ValueError, match="invalid truth value '%s'".format(value)):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I don't like this single test with a loop.
  2. The error string should be a constant without format.

Please check pytest's parametrize

@@ -0,0 +1,21 @@
import pytest
from util import strtobool
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utils is a symptom of lack of a proper abstraction. Please, do not use it. Keep the strtobool function on the main file decouple.py since it's not used anywhere else.

util.py Outdated
@@ -0,0 +1,9 @@
def strtobool(value):
value = value.lower()
if value in ["y", "yes", "t", "true", "on", "1"]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These comparisons are O(N) and always recreate the list. Make the list definition global and use a set instead of a list.

decouple.py Show resolved Hide resolved
decouple.py Show resolved Hide resolved
decouple.py Show resolved Hide resolved
tests/test_strtobool.py Show resolved Hide resolved
henriquebastos added a commit that referenced this pull request Feb 2, 2022
@henriquebastos henriquebastos merged commit 7e90cd3 into HBNetwork:master Feb 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

distutils DeprecationWarning in Python 3.10
3 participants